setwd("")
data<-read.csv("02_Clean Racial Shift Full Replication Proprietary.csv")

# Recode
data$educ4 <- NA
data$educ4[which(data$education <= 2)] <- 1 # HS or Less
data$educ4[which(data$education >= 3 & data$education <= 5)] <- 2 # Some college
data$educ4[which(data$education == 6)] <- 3 # College
data$educ4[which(data$education >= 7)] <- 4 # Grad School

data$pid7_nodk <- ifelse(data$political_party_preference < 98, data$political_party_preference, NA)
data$pid3 <- NA
data$pid3[which(data$pid7_nodk < 4)] <- -1
data$pid3[which(data$pid7_nodk == 4)] <- 0
data$pid3[which(data$pid7_nodk > 4)] <- 1

data$ft_check_same <- ifelse(data$Trump_FT == data$Biden_FT & 
                                    data$Biden_FT == data$Swift_FT & 
                                    data$Swift_FT == data$Kimmel_FT, 
                                  1, 0)


# Withdraw ----------------------------------------------------------------

data$remove_data[which(!is.na(data$Treatment) & data$remove_data != "Yes")] <- "No"
data$remove_data[which(data$remove_data == "")] <- NA

# Age
mean(data$age[which(data$remove_data == "No")], na.rm = T)
mean(data$age[which(data$remove_data == "Yes")], na.rm = T)
t.test(age ~ remove_data, data)

# Education
prop.table(table(data$educ4, data$remove_data), 2)
chisq.test(table(data$educ4, data$remove_data))

# Gender
prop.table(table(data$gender, data$remove_data), 2)
chisq.test(table(data$gender, data$remove_data))

# PID
prop.table(table(data$pid3, data$remove_data), 2)
chisq.test(table(data$pid3, data$remove_data))

# Ideo
mean(data$cons_ideo_scale[which(data$remove_data == "No")], na.rm = T)
mean(data$cons_ideo_scale[which(data$remove_data == "Yes")], na.rm = T)
t.test(cons_ideo_scale ~ remove_data, data)

# treatment
prop.table(table(data$Treatment, data$remove_data), 2)
chisq.test(table(data$Treatment, data$remove_data))

# fact check
prop.table(table(data$mc_correct, data$remove_data), 2)
t.test(mc_correct ~ remove_data, data)

# straightlining
prop.table(table(data$ft_check_same, data$remove_data), 2)
t.test(ft_check_same ~ remove_data, data)